﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ChanageJavaPackage
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

         private void btnGenerate_Click(object sender, EventArgs e)
        {
            // 打开目录，
            string srcProject = txtSrcProject.Text.Trim();
            string destProject = txtDestProject.Text.Trim();
            var srcProjectDir = new DirectoryInfo(srcProject);
            var destProjectDir = new DirectoryInfo(destProject);

            dealDir(srcProjectDir, destProjectDir);
        }

        private void dealDir(DirectoryInfo srcProjectDir, DirectoryInfo destProjectDir)
        {
            // 遍历目录
            DirectoryInfo[] dirs = srcProjectDir.GetDirectories();
            foreach (DirectoryInfo dir in dirs)
            {
                // 隐藏的忽略，如.git
                if ((dir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                {
                    continue;
                }
                // .idea、 .settings等忽略
                if (dir.Name.StartsWith("."))
                {
                    continue;
                }
                Console.WriteLine(dir.FullName);
                dealDir(dir, destProjectDir);
            }
            // 遍历文件
            FileInfo[] files = srcProjectDir.GetFiles();
            foreach (var file in files)
            {
                // 隐藏的忽略，如.git
                if ((file.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                {
                    continue;
                }
                // .idea、 .settings等忽略
                if (file.Name.StartsWith("."))
                {
                    continue;
                }
                // .class 忽略
                if (file.Extension.EndsWith(".class"))
                {
                    continue;
                }
                Console.WriteLine(file.FullName);
                if (file.Extension.EndsWith("pom.xml"))
                {
                    dealPomXml(file, destProjectDir);
                } 
                else if (file.Extension.EndsWith(".java"))
                {
                    dealJavaFile(file, destProjectDir);
                }
            }
        }

        private void dealPomXml(FileInfo file, DirectoryInfo destProjectDir)
        {
            // 打开file,查找替换
            //file.FullName = 
            // 写入destProjectDir
            //throw new NotImplementedException();
        }

        private void dealJavaFile(FileInfo file, DirectoryInfo destProjectDir)
        {
            throw new NotImplementedException();
        }

    }
}
